﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server


Partial Public Class StoredProcedures
    Private Shared Sub CmdExecNoArguments(ByVal FileNameWithPath As String, _
                                          Optional ByRef StdOutObj As System.IO.StreamReader = Nothing, _
                                          Optional ByRef StdErrObj As System.IO.StreamReader = Nothing)
        Try
            Dim _oProcess As New Process
            Dim _oPSI As New ProcessStartInfo(FileNameWithPath)

            _oPSI.UseShellExecute = False
            _oPSI.RedirectStandardOutput = True
            _oPSI.RedirectStandardError = True

            _oProcess.StartInfo = _oPSI

            _oProcess.Start()

            StdOutObj = _oProcess.StandardOutput
            StdErrObj = _oProcess.StandardError
        Catch ex As Exception
            Throw New Exception("Exception Occurred in: CmdExecNoArguments", ex)
        End Try
    End Sub

    Private Shared Function CmdExecWithArguments(ByVal FileNameWithPath As String, _
                                                 ByVal CmdArguments As String, _
                                                 Optional ByRef StdOutObj As System.IO.StreamReader = Nothing, _
                                                 Optional ByRef StdErrObj As System.IO.StreamReader = Nothing) As Integer
        Try
            Dim _oProcess As New Process
            Dim _oPSI As New ProcessStartInfo(FileNameWithPath, CmdArguments)

            _oPSI.UseShellExecute = False
            _oPSI.RedirectStandardOutput = True
            _oPSI.RedirectStandardError = True

            _oProcess.StartInfo = _oPSI

            _oProcess.Start()

            StdOutObj = _oProcess.StandardOutput
            StdErrObj = _oProcess.StandardError
        Catch ex As Exception
            Throw New Exception("Exception Occurred in: CmdExecWithArguments", ex)
        End Try
    End Function
End Class
